import 'package:extended_text_library/extended_text_library.dart';
import 'package:flutter/material.dart';

import '../emoji_util.dart';

class EmojiText extends SpecialText {
  EmojiText(TextStyle? textStyle, {this.start}) : super(EmojiText.flag, ']', textStyle);
  static const String flag = '[';
  final int? start;

  @override
  InlineSpan finishText() {
    final String key = toString();

    final emojiM = EmojiUtil.emojiMap();
    if (emojiM.containsKey(key)) {
      double size = 20;

      return ImageSpan(
        AssetImage(
          emojiM[key]!,
        ),
        actualText: key,
        imageWidth: size,
        imageHeight: size,
        start: start!,
        fit: BoxFit.cover,
        margin: const EdgeInsets.only(left: 2, right: 2, top: 2, bottom: 0),
      );
    }

    return TextSpan(text: toString(), style: textStyle);
  }
}
